Opened 16 years ago
Closed 16 years ago
#227 closed defect (invalid)
Parser error when declaring a pointer and assigning it memory with malloc on same line.
| Reported by: | dfix | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | Release 1.0 |
| Component: | examples | Version: | 1.0 |
| Keywords: | malloc, pointer, parser error | Cc: |
Description
Separating these two operations (declaring the pointer and using malloc) will result in a different error.
typedef struct Node{
struct Node* next;
int value;
} Node;
void main () {
Node *a = malloc(sizeof(Node));
free(a);
}
edu.udel.cis.vsl.tass.front.minimp.parser.SyntaxError: Syntax error found in file: linkedListDeletion.mmp, on line: 10:11 Undefined variable malloc at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.reportSyntaxError(TreeParser.java:2921) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processEvaluatedFunctionExpr(TreeParser.java:2119) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processPrimaryExpr(TreeParser.java:2093) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processPostfixExpr(TreeParser.java:1867) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processUnaryExpr(TreeParser.java:1790) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processMultiplicativeExpr(TreeParser.java:1740) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processAdditiveExpr(TreeParser.java:1691) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processRelationalExpr(TreeParser.java:1636) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processEqualityExpr(TreeParser.java:1584) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processLogicalAndExpr(TreeParser.java:1552) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processLogicalOrExpr(TreeParser.java:1521) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processIfThenElseExpr(TreeParser.java:1486) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processAssignExpr(TreeParser.java:1479) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processExpr(TreeParser.java:1422) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processInitializer(TreeParser.java:979) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processDeclarationBody(TreeParser.java:622) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processDeclaration(TreeParser.java:475) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processDeclarationList(TreeParser.java:348) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processFunctionBody(TreeParser.java:1379) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processFunction(TreeParser.java:1274) at edu.udel.cis.vsl.tass.front.minimp.parser.TreeParser.processAST(TreeParser.java:286) at edu.udel.cis.vsl.tass.front.minimp.ModelExtractor.extract(ModelExtractor.java:29) at edu.udel.cis.vsl.tass.front.minimp.ModelExtractor.extractModel(ModelExtractor.java:54) at linkedList.LinkedListTest.testVerifyLinkedListDeletion(LinkedListTest.java:67) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41) at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) at org.junit.runners.ParentRunner.run(ParentRunner.java:220) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197
Note:
See TracTickets
for help on using tickets.

This is not grammatically correct in MiniMP. "p=malloc(e)" is a statement, but "malloc(e)" is not an expression, because it has side-effects. Since it is not an expression, it cannot be used as an initializer. This must be broken down into two steps: declaration, followed by the malloc statement.
MiniMP != C. It is close, but there are a lot of things you can do in C that you cannot do in our intermediate language.