You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Java's enum, record, and sealed interface could be utilized for a compact representation of the abstract syntax, residing in a single module rather than a package.
It follows a grammar and a suggestion for a contemporary representation. CMM.cf:
-- Grammar for small C/C++/Java-like language called C-- (C minus minus).
-- # Programs are lists of function definitions.
PDefs. Program::= [Def] ;
-- ## Function definition.
DFun. Def::=TypeId"(" [Arg] ")""{" [Stm] "}";terminatorDef"";
-- ## Function parameters.
ADecl. Arg::=TypeId;separatorArg",";
-- # Statements.
SDecls. Stm::=Type [Id] ";";SInit. Stm::=TypeId"="Exp";";SBlock. Stm::="{" [Stm] "}";SExp. Stm::=Exp";";SReturn. Stm::="return"Exp";";SWhile. Stm::="while""("Exp")"Stm;SIfElse. Stm::="if""("Exp")"Stm"else"Stm;terminatorStm"";
-- # Expressions.
-- ## Atomic expressions.
-- ### Literals.
EInt. Exp6::=Integer;EDouble. Exp6::=Double;
-- ### Identifiers and function calls.
EId. Exp6::=Id;EApp. Exp6::=Id"(" [Exp] ")"; -- Restricted to Id.
-- ### Increment and decrement.
EPost. Exp6::=IdIncDecOp; -- Restricted to Id.EPre. Exp6::=IncDecOpId; -- Restricted to Id.
-- ## Compound expressions.
-- ### Multiplicative operations.
EMul. Exp5::=Exp5MulOpExp6; -- Left assoc.
-- ### Additive operations.
EAdd. Exp4::=Exp4AddOpExp5; -- Left assoc.
-- ### Comparison.
ECmp. Exp3::=Exp4CmpOpExp4; -- Non-assoc.
-- ### Boolean operations.
EAnd. Exp2::=Exp2"&&"Exp3; -- Left assoc.EOr. Exp1::=Exp1"||"Exp2; -- Left assoc.
-- ### Assignment.
EAss. Exp::=Id"="Exp; -- Right assoc. Restricted to Id.coercionsExp 6 ;separatorExp","; -- Function arguments are comma-separated.
-- ## Operators.
OInc. IncDecOp::="++";ODec. IncDecOp::="--";OTimes. MulOp::="*";ODiv. MulOp::="/";OPlus. AddOp::="+";OMinus. AddOp::="-";OLt. CmpOp::="<";OGt. CmpOp::=">";OLtEq. CmpOp::="<=";OGtEq. CmpOp::=">=";OEq. CmpOp::="==";ONEq. CmpOp::="!=";
-- # Types and identifiers
rulesType::="bool" | "int" | "double" | "void";tokenId (letter (letter | digit | '_')*) ;separatornonemptyId",";
-- # Comment syntax
comment"#";comment"//";comment"/*""*/";
Java's
enum
,record
, andsealed interface
could be utilized for a compact representation of the abstract syntax, residing in a single module rather than a package.It follows a grammar and a suggestion for a contemporary representation.
CMM.cf
:Java syntax representation:
The text was updated successfully, but these errors were encountered: