Skip to content

Commit f0cc827

Browse files
analyzer outline, small ohm deletion
1 parent 055b663 commit f0cc827

File tree

2 files changed

+24
-121
lines changed

2 files changed

+24
-121
lines changed

src/analyzer.js

+23-120
Original file line numberDiff line numberDiff line change
@@ -214,137 +214,38 @@ export default function analyze(match) {
214214
Epilogue(_epilogue, _nl_0, directions, _endEpilogue, _nl_1) {
215215
return directions.rep()
216216
},
217-
/* Direction(line){
217+
Direction(line){
218218
return line.rep()
219219
},
220220
DialogueLine(stmt){
221221
return stmt.rep()
222222
},
223223
CastLine(decl){
224224
return decl.rep()
225-
}, */
225+
},
226226
PrintStmt(_print, expression, _dd, _nl) {},
227227
ForStmt(_for, type, id, _in, range, _colon, block) {
228228
return core.forStatement(id.sourceString, range.rep(), block.rep())
229229
},
230-
MemberExp_self(_given, name) {},
231-
MemberExp(exp) {},
232-
/*Program(blocks) {
233-
return core.program(blocks.children.map(e => e.rep()))
234-
//return core.script(prologue.rep(), acts.rep(), epilogue.rep())
235-
},
236-
// How do we check PROLOGUE/ACT/ EPILOGUE?
237-
Block(_open, statements, _close) {
238-
return core.block(statements.rep())
239-
},
240-
// is type.rep() ok?
241-
VarDecl(_cast, type, id, _as, exp, _dd, _nl) {
242-
const initializer = exp.rep()
243-
const variable = core.variable(id.sourceString, type.rep(), initializer.type)
244-
= mustNotAlreadyBeDeclared(id.sourceString, { at: id })
245-
context.add(id.sourceString, variable)
246-
return core.variableDeclaration(variable, initializer)
247-
},
248-
FuncDecl(_startFunc, type, id, _has, parameters, _colon, _nl, block, _endFunc) {
249-
const func = core.func(id.sourceString)
250-
mustNotAlreadyBeDeclared(id.sourceString, { at: id })
251-
context.add(id.sourceString, func)
252-
253-
context = context.newChildContext({ inLoop: false, function: func })
254-
const params = parameters.rep()
255-
256-
const paramTypes = params.map(p => p.type)
257-
const returnType = type.children[0].rep()
258-
func.type = core.functionType(paramTypes, returnType)
259-
260-
const body = block.rep()
261-
262-
context = context.parent
263-
return core.functionDeclaration(func, params, body)
264-
},
265-
ClassDecl(_class, name, _colon, fields, methods, constructor) {
266-
const className = name.sourceString
267-
mustNotAlreadyBeDeclared(className, name)
268-
const fieldTypes = fields.rep()
269-
const methodTypes = methods.rep()
270-
const constructorType = constructor.rep()
271-
context.add(className, { type: { kind: "ClassType", name: className, fields: fieldTypes, methods: methodTypes, constructor: constructorType } })
272-
return core.classDeclaration(className, fieldTypes, methodTypes, constructorType)
273-
},
274-
// may need to replace block with ctorbody
275-
Constructor(_constructor, parameters, _colon, block) {
276-
const constructorParameters = parameters.rep()
277-
context = context.newChildContext({ function: { type: { kind: "FunctionType", paramTypes: constructorParameters, returnType: VOID } } })
278-
const body = block.rep()
279-
context = context.parent
280-
return core.constructor(constructorParameters, body)
281-
},
282-
MemberExp_self(_given, name) {
283-
const fieldName = name.sourceString
284-
const entity = context.lookup(fieldName)
285-
must(entity, `Identifier ${fieldName} not declared`, name)
286-
return core.variable(fieldName, entity.type)
287-
},
288-
Params(_has, params, _colon) {
289-
return params.asIteration().children.map(e => e.rep())
290-
},
291-
Param(type, id) {
292-
const param = core.variable(id.sourceString, false, type.rep())
293-
mustNotAlreadyBeDeclared(param.name, { at: id })
294-
context.add(param.name, param)
295-
return param
296-
},
297-
// Direction
298-
// DialogueLine
299-
PrintStmt(_print, expression) {
300-
return core.printStatement(expression.rep())
301-
},
302-
ForStmt(_for, _open, iterator, _in, collection, _close, body) {
303-
return core.forStatement(iterator.sourceString, collection.rep(), body.rep())
304-
},
305-
// the following is copilot generated
306-
IfStmt(_if, exp, block) {
307-
const test = exp.rep()
308-
mustHaveBooleanType(test, { at: exp })
309-
const consequent = block.rep()
310-
return core.ifStatement(test, consequent, null)
311-
},
312-
ElseIf(_else, _if, exp, block) {
313-
const test = exp.rep()
314-
mustHaveBooleanType(test, { at: exp })
315-
const consequent = block.rep()
316-
return core.elseIfStatement(test, consequent)
317-
},
318-
ElseStmt(_else, block) {
319-
return core.elseStatement(block.rep())
320-
},
321-
WhileStmt(_while, exp, block) {
322-
const test = exp.rep()
323-
mustHaveBooleanType(test, { at: exp })
324-
context = context.newChildContext({ inLoop: true })
325-
const body = block.rep()
326-
context = context.parent
327-
return core.whileStatement(test, body)
328-
},
329-
ReturnStmt(returnKeyword, exp) {
330-
mustBeInAFunction({ at: returnKeyword })
331-
mustReturnSomething(context.function, { at: returnKeyword })
332-
const returnExpression = exp.rep()
333-
mustBeReturnable(returnExpression, { from: context.function }, { at: exp })
334-
return core.returnStatement(returnExpression)
335-
},
336-
AssignmentStmt(_recast, variable, _as, exp, _dd, _nl) {
337-
const target = variable.rep()
338-
const source = exp.rep()
339-
mustBeAssignable(source, { toType: target.type }, { at: variable })
340-
return core.assignmentStatement(target, source)
341-
},
342-
Type_id(id) {
343-
const type = context.lookup(id.sourceString)
344-
mustHaveBeenFound(type, id.sourceString, { at: id })
345-
mustBeAType(type, { at: id })
346-
return type
347-
},*/
230+
IfStmt(_if, id, _is, exp, _colon, _nl, block, elseifstmt, elsestmt){},
231+
ElseIf(_elseif, id, _is, exp, _colon, _nl, block){},
232+
Else(_else, _colon, _nl, block){},
233+
WhileStmt(_while, exp, _colon, _nl, block){},
234+
Block(directions){},
235+
ReturnStmt(_return, exp, _dd, _nl){},
236+
CastDecl(_cast, type, id, _as, exp, _dd, _nl){},
237+
RecastDecl(_recast, id, _as, exp, _dd, _nl){},
238+
FuncDecl(_function, type, id, _has, params, _colon, _nl_0, block, _endfunction, _nl_1){},
239+
ClassDecl(_class, id, _colon, _nl_0, decl, _endclass, _nl_1){},
240+
Constructor(_ctor, _has, params, _colon, _nl, ctorbody, _endctor, _nl){},
241+
/* CtorBody() TO DO need field
242+
MemberExp_self(_given, name) {},
243+
MemberExp(exp) {},
244+
*/
245+
Params(params, _colon){},
246+
Param(type, id){},
247+
RangeFunc(_range, _from, exp_0, _comma, exp_1){},
248+
348249
Exp_booleanOr(exps, _or, exp) {
349250
let right = exp.rep()
350251
mustHaveBooleanType(right, { at: exp })
@@ -414,6 +315,8 @@ export default function analyze(match) {
414315
mustAllHaveSameType(elements, { at: args })
415316
return core.listExpression(elements)
416317
},
318+
Exp6(lit){},
319+
Type(type, list){},
417320
true(_) {
418321
return true
419322
},

src/blvd.ohm

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ blvd {
5656
| Exp6
5757
Exp6 = "(" Exp ")" --parens
5858
| "["ListOf<Exp, ","> "]" --listexp
59-
| message --stringlit
59+
| message
6060
| (true | false)
6161
| id
6262
| num

0 commit comments

Comments
 (0)