options { JDK_VERSION = "1.6"; STATIC = false; IGNORE_CASE = true; } PARSER_BEGIN(ExpressParser) package org.simantics.express.parser; import org.simantics.express.ast.types.*; import org.simantics.express.ast.expressions.*; import java.util.List; import java.util.ArrayList; public class ExpressParser { } PARSER_END(ExpressParser) /* Lexer */ SKIP: { | | } TOKEN: { ";" | "(" | ")" | "\\" | "?" | "[" | "]" | "{" | "}" | "|" | "&" | ":" | ":=" | ":=:" | ":<>:" | "," | "." | "=" | "<" | ">" | "<=" | ">=" | "/" | "+" | "-" | "*" | "@" | "<*" | "<>" | "**" | "||" | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "." ()? (("e"|"E") ("+"|"-")? )? > } /* Parser */ void document() : {} { (schema())* } void schema() : {} { ";" (interface_())* (constDecl())? (decl())* ";" } void interface_() : {} { ( "(" references() ")" )? ";" | ( "(" references() ")" )? ";" } void references() : {} { reference() ("," reference())* } void reference() : {} { ( )? } void constDecl() : {} { ( ":" typeB() ":=" exp() ";")+ ";" } void decl() : {} { ruleDecl() | decl0() } void ruleDecl() : {} { "(" idents() ")" ";" localDecls() (statement())* where() ";" } void decl0() : {} { entityDecl() | functionDecl() | procedureDecl() | typeDecl() | subtypeConstraintDecl() } void entityDecl() : {} { (supertype())? (subtype())? ";" (attributes() ":" ()? typeB() ";")* ( (attribute() ":" typeB() ":=" exp() ";")+ )? ( (attribute() ":" typeI() attribute() ";")+ )? ( ( ( LOOKAHEAD(2) ":")? attributes() ";")+ )? (where())? ";" } void localDecls() : {} { (decl0())* (constDecl())? ( ( idents() ":" typeP() (":=" exp())* ";")+ ";")? } void functionDecl() : {} { ("(" parameter() (";" parameter())* ")")? ":" typeP() ";" localDecls() (statement())+ ";" } void procedureDecl() : {} { ("(" parameterP() (";" parameterP())* ")")? ";" localDecls() (statement())+ ";" } void typeDecl() : {} { "=" typeU() ";" (where())? ";" } void subtypeConstraintDecl() : {} { ";" ( ";")? (supertypeExpression() ";")? ";" } void where() : {} { ( ( LOOKAHEAD(2) ":")? exp() ";")+ } void parameter() : {} { idents() ":" typeP() } void parameterP() : {} { parameter() | parameterP() } void supertype() : {} { "(" supertypeExpression() ")" | ( "(" supertypeExpression() ")")? } void supertypeExpression() : {} { supertypeExpression2() ( supertypeExpression2())* } void supertypeExpression2() : {} { supertypeExpression3() ( supertypeExpression3())* } void subtype() : {} { "(" idents() ")" } void supertypeExpression3() : {} { | "(" supertypeExpression() ("," supertypeExpression())* ")" | "(" supertypeExpression() ")" } void attribute() : {} { | "\\" "." ( )? } void attributes() : {} { attribute() ("," attribute())* } ExpType typeBI() : {} { { return ExpBoolean.INSTANCE; } | /* */ { return ExpReal.INSTANCE; } | { return ExpNumber.INSTANCE; } | ( "(" exp1() ")")? ( )? { return ExpBinary.INSTANCE; } | { return ExpLogical.INSTANCE; } | ( "(" exp1() ")")? ( )? { return ExpString.INSTANCE; } | { return ExpInteger.INSTANCE; } } ExpType typeB() : { ExpType type; } { type=typeN() { return type; } | type=typeBI() { return type; } | type=typeA() { return type; } } ExpType typeA() : { ExpType type; } { bound() type=typeB() { return new ExpBag(type); } | bound() ()? ()? type=typeB() { return new ExpArray(type); } | bound() ()? type=typeB() { return new ExpList(type); } | bound() type=typeB() { return new ExpSet(type); } } ExpType typeI() : { ExpType type; } { type=typeN() { return type; } | bound() type=typeN() { return new ExpBag(type); } | bound() type=typeN() { return new ExpSet(type); } } ExpType typeN() : { Token tt; } { tt= { return new ExpTypeName(tt.image); } } ExpType typeP() : { ExpType type; } { type=typeBI() { return type; } | type=typeN(){ return type; } | bound() type=typeP() { return new ExpBag(type); } | bound() ()? ()? type=typeP() { return new ExpArray(type); } | bound() ()? type=typeP() { return new ExpList(type); } | bound() type=typeP() { return new ExpSet(type); } | (":" )? { return ExpGeneric.INSTANCE; } | { return ExpGenericEntity.INSTANCE; } | (":" )? type=typeP() { return new ExpAggregate(type); } } ExpType typeU() : {} { { ExpType type; } type=typeB() { return type; } | LOOKAHEAD(3) ()? ()?